/* Copyright (c) [2020] juruoyun developer team
   Juruoyun basic lib is licensed under the Mulan PSL v1.
   You can use this software according to the terms and conditions of the Mulan PSL v1.
   You may obtain a copy of Mulan PSL v1 at:
      http://license.coscl.org.cn/MulanPSL
   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
   PURPOSE.
   See the Mulan PSL v1 for more details.*/
#include "jbl_time.h"
#if JBL_TIME_ENABLE==1
/*******************************************************************************************/
/*                            依赖jbl_gc jbl_malloc jbl_ying jbl_exception                */
/*******************************************************************************************/
#include "jbl_exception.h"
#include "jbl_gc.h"
#include "jbl_malloc.h"
#include "jbl_ying.h"
#include <sys/time.h>
/*******************************************************************************************/
/*                            联动jbl_string jbl_var                                       */
/*******************************************************************************************/
#include "jbl_string.h"
#include "jbl_var.h"
/*******************************************************************************************/
/*                            全局变量定义                                                */
/*******************************************************************************************/
jbl_int8		jbl_time_time_zone=JBL_TIME_DEFAULT_TIME_ZONE;
jbl_var_operators_new(jbl_time_operators,jbl_time_free,jbl_time_copy,jbl_time_space_ship,jbl_time_json_encode,jbl_time_view_put,jbl_time_json_put);
/*******************************************************************************************/
/*                            以下函实现时间基本操作                                     */
/*******************************************************************************************/
jbl_time * jbl_time_new()
{
	return jbl_time_init(jbl_malloc(sizeof(jbl_time)));
}
JBL_INLINE jbl_time * jbl_time_init(jbl_time *this)
{
	if(!this)jbl_exception("NULL POINTER");
	jbl_gc_init(this);
	jbl_gc_plus(this);
	jbl_pthread_lock_init(this);
	jbl_var_set_operators(this,&jbl_time_operators);
	this->t=0;
	return this;
}
JBL_INLINE jbl_time * jbl_time_free(jbl_time *this)
{
	if(!this)return NULL;
    jbl_pthread_lock_wrlock(this);
	jbl_gc_minus(this);
	if(!jbl_gc_refcnt(this))
	{
		if(jbl_gc_is_ref(this))
            jbl_time_free((jbl_time*)(((jbl_reference*)this)->ptr));
        jbl_pthread_lock_free(this);
		jbl_free(this);
	}
    else{jbl_pthread_lock_unwrlock(this);}
	return NULL;
}
JBL_INLINE jbl_time * jbl_time_set(jbl_time * this,jbl_int64 time)
{
	if(!this)this=jbl_time_new();
    jbl_time * thi=jbl_refer_pull_wrlock(this);
	thi->t=time;
	jbl_refer_pull_unwrlock(this);
    return this;
}
JBL_INLINE jbl_int64 jbl_time_get(jbl_time * this)
{
	if(!this)return 0;
    jbl_time * thi=jbl_refer_pull_rdlock(this);
	jbl_int64 time=thi->t;
	jbl_refer_pull_unrdlock(this);
    return time;
}
JBL_INLINE jbl_time * jbl_time_copy(jbl_time * that)
{
	if(!that)return NULL;
	return jbl_time_set(NULL,jbl_time_get(that));
}
JBL_INLINE jbl_time * jbl_time_add_second(jbl_time * this,jbl_int64 second)
{
	if(!this)this=jbl_time_new();
    jbl_time * thi=jbl_refer_pull_wrlock(this);
	thi->t+=1000*second;
	jbl_refer_pull_unwrlock(this);
    return this;
}
/*******************************************************************************************/
/*                            以下函实现时间获取操作                                     */
/*******************************************************************************************/
JBL_INLINE jbl_time * jbl_time_now(jbl_time *this)
{
	struct timeval tv;
	gettimeofday(&tv,NULL);
	return jbl_time_set(this,(((jbl_int64)tv.tv_sec)*1000)+(tv.tv_usec/1000));
}
void jbl_time_decode(jbl_time *this,jbl_time_decoded *tt)
{
	if(!tt)return;
	if(!this){tt->year=0,tt->ms=0,tt->week=0,tt->dom=0,tt->day=0,tt->hour=0,tt->month=0,tt->minute=0,tt->second=0,tt->isleap=0;return;}
	jbl_int64 ts=jbl_time_get(this);
	jbl_int64 days=0,dayTmp=0,secs=0;
	if(jbl_time_time_zone==JBL_TIME_ZONE_ASIA_SHANGHAI)
		ts+=8*3600000;
	if(ts>0)
	{
		tt->ms=(jbl_uint32)(ts%1000),ts/=1000,days=ts/86400,secs=ts%86400;
		for(tt->year=1970;days>0;++tt->year)
			if(days>=(dayTmp=(365+(tt->isleap=jbl_time_if_leap_year(tt->year)))))
				days-=dayTmp;
			else
				break;
		for(tt->month=1;tt->month<12;++tt->month)
			if(days>=(dayTmp=jbl_time_get_day_of_month(tt->month,tt->year)))
				days-=dayTmp;
			else
				break;
		tt->month=tt->month;
        tt->day=(jbl_uint16)(days+1);
        tt->dom=(jbl_uint8)(dayTmp);
	}
	else
	{
		tt->ms=(jbl_uint32)(1000-(-ts)%1000),ts=((ts-(1000-tt->ms))/1000),((tt->ms==1000)?(tt->ms=0):0),secs=-(ts%86400),secs=(secs==0)?0:(86400-secs),days=(ts-secs)/86400;
		for(tt->year=1969;days<0;--tt->year)
			if((-days)>=(dayTmp=(365+(tt->isleap=jbl_time_if_leap_year(tt->year)))))
				days+=dayTmp;
			else
				break;
		for(tt->month=12;tt->month>0;--tt->month)
			if(days<(dayTmp=jbl_time_get_day_of_month(tt->month,tt->year)))
				days+=dayTmp;
			else
				break;
		tt->dom=(jbl_uint8)(dayTmp);
		if(days>jbl_time_get_day_of_month((jbl_uint8)(tt->month+1),tt->year))
			++tt->month,days-=(tt->dom=jbl_time_get_day_of_month(tt->month,tt->year));
		tt->month=(jbl_uint8)(tt->month+1);
        tt->day=(jbl_uint16)(days+1);
	}
	tt->hour  =(jbl_uint8)(secs/3600),secs%=3600;
    tt->minute=(jbl_uint8)(secs/60);
    tt->second=(jbl_uint8)(secs%60);
	tt->week=jbl_time_get_weekday(tt->day,tt->month,tt->year);
}

/*******************************************************************************************/
/*                            以下函实现时间比较操作                                      */
/*******************************************************************************************/
JBL_INLINE char jbl_time_space_ship(jbl_time *this,jbl_time *that)
{
	jbl_int64 t=jbl_time_minus(this,that);
	return (t>0)?1:((t<0)?(-1):0);
}
/*******************************************************************************************/
/*                            以下函实现特殊时间判断操作                                 */
/*******************************************************************************************/
JBL_INLINE jbl_uint8 jbl_time_if_leap_year(jbl_int32 year){return (((year%400)==0)?1:(((year%100)==0)?0:(((year%4)==0)?1:0)));}
JBL_INLINE jbl_uint8 jbl_time_get_day_of_month(jbl_uint8 month,jbl_int32 year)
{
    static const jbl_uint8 dpm[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    if(month==0||month>12)  return 0;
    if(month==2)            return (jbl_uint8)(dpm[1]+jbl_time_if_leap_year(year));
    return (dpm[month-1]);
}
JBL_INLINE jbl_uint8 jbl_time_get_weekday(jbl_uint16 day,jbl_uint8 month,jbl_int32 year)
{
    if((month==1)||(month==2))month=(jbl_uint8)(12+month),year--;
    return (jbl_uint8)((day+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7+1);
}
jbl_uint8 jbl_time_if_dst(jbl_uint16 day,jbl_uint8 month,jbl_int32 year)
{
    if(day||month||year)day=0,month=0,year=0;
	if(jbl_time_time_zone==JBL_TIME_ZONE_ASIA_SHANGHAI)
	{
		
		
		
	}
	return false;
}
jbl_time_key __jbl_time_key_scaner(const unsigned char * YYCURSOR,const unsigned char * YYLIMIT,const unsigned char **addr)
{
	#define YYCTYPE		unsigned char
	#define YYFILL(n)	return JBL_TIME_KEY_END;
    /*!re2c
		[^%jdDlNSwzWFmMntLoYyaABgGhHisueIOPTZU]		{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_UNDEFINED;}	
		"%"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_ESCAPE;}
		
		"j"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_DOM;}
		"d"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_DOMWZ;}
		"D"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_DOW3;}
		"l"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_DOWA;}
		"N"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_DOWN;}
		"S"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_DOMS;}
		"w"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_DOWNF0;}
		"z"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_DOY;}
		
		"W"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_WOY;}
		
		"F"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_M;}
		"m"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_MNWZ;}
		"M"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_M3;}
		"n"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_MN;}
		"t"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_TDOM;}
		
		"L"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_YILY;}
		"o"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_YISO;}
		"Y"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_Y;}
		"y"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_Y2;}
		
		"a"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_SA;}
		"A"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_A;}
		"B"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_SWATCH;}
		"g"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_H12;}
		"G"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_H12WZ;}
		"h"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_H24;}
		"H"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_H24WZ;}
		"i"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_MWZ;}
		"s"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_SWZ;}
		"u"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_MSWZ;}
		
		"e"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_TZT;}
		"I"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_IDST;}
		"O"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_HTG;}
		"P"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_DWG;}
		"T"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_TZ;}
		"Z"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_STG;}
		"U"				{if(addr)*addr=YYCURSOR;return JBL_TIME_KEY_S;}
		
	 */
	#undef YYCTYPE
	#undef YYFILL
}

#if JBL_STRING_ENABLE==1
/*******************************************************************************************/
/*                            以下函实现时间对字符串操作                                */
/*******************************************************************************************/
jbl_string * jbl_time_to_string_format(jbl_time *this,jbl_string *result,const unsigned char * format)
{
	jbl_time_decoded tt;
	jbl_time_decode(this,&tt);
	jbl_string_size_type n=jbl_strlen(format),i=0;
	const unsigned char * addr;
	jbl_time_key key;
	const char * doms[]	={"th","st","nd","rd","th","th","th","th","th","th"};
	const char * dowa[]	={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
	const char * dow3[]	={"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
	const char * m[]	={"January","February","March","April","May","June","July","August","September","October","November","December"};
	const char * m3[]	={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
	const char * sa[]	={"am","pm"};
	const char * a[]	={"AM","PM"};
    jbl_refer_pull_wrlock(result);
	while((key=__jbl_time_key_scaner(format+i,format+n,&addr))!=JBL_TIME_KEY_END)
	{
		i=(jbl_string_size_type)(addr-format);
		switch(key)
		{
			case JBL_TIME_KEY_UNDEFINED	:result=jbl_string_add_char(result,format[i-1])					;break;			
			case JBL_TIME_KEY_ESCAPE	:if(format[i])result=jbl_string_add_char(result,format[i]),++i	;break;			
			case JBL_TIME_KEY_END		:return result;break;
			
			case JBL_TIME_KEY_DOM		:result=jbl_string_add_uint(result,tt.day)					    ;break;
			case JBL_TIME_KEY_DOMWZ		:result=jbl_string_add_uint_length(result,tt.day,2,'0')		    ;break;
			case JBL_TIME_KEY_DOMS		:result=jbl_string_add_chars(result,UC doms[tt.day%10])			;break;
			case JBL_TIME_KEY_DOW3		:result=jbl_string_add_chars(result,UC dow3[tt.week-1])			;break;
			case JBL_TIME_KEY_DOWA		:result=jbl_string_add_chars(result,UC dowa[tt.week-1])			;break;
			case JBL_TIME_KEY_DOWN		:result=jbl_string_add_uint(result,tt.week)					    ;break;
			case JBL_TIME_KEY_DOWNF0	:result=jbl_string_add_uint(result,(jbl_uint8)(tt.week-1))		;break;
			case JBL_TIME_KEY_DOY		:break;
			
			case JBL_TIME_KEY_WOY		:break;
			
			case JBL_TIME_KEY_M			:result=jbl_string_add_chars(result,UC m[tt.month-1])			;break;	
			case JBL_TIME_KEY_MNWZ		:result=jbl_string_add_uint_length(result,tt.month,2,'0')		;break;
			case JBL_TIME_KEY_M3		:result=jbl_string_add_chars(result,UC m3[tt.month-1])			;break;	
			case JBL_TIME_KEY_MN		:result=jbl_string_add_uint(result,tt.month)					;break;	
			case JBL_TIME_KEY_TDOM		:result=jbl_string_add_uint(result,tt.dom)					    ;break;			

			case JBL_TIME_KEY_YILY		:result=jbl_string_add_uint(result,tt.isleap)					;break;
			case JBL_TIME_KEY_Y			:result=jbl_string_add_int_length(result,tt.year,4,'0')		    ;break;
			case JBL_TIME_KEY_YISO		:break;
			case JBL_TIME_KEY_Y2		:result=jbl_string_add_int_length(result,tt.year%100,2,'0')	    ;break;	
			
			
			
			case JBL_TIME_KEY_SA		:result=jbl_string_add_chars(result,UC sa[tt.hour/12])			;break;
			case JBL_TIME_KEY_A			:result=jbl_string_add_chars(result,UC a[tt.hour/12])			;break;
			case JBL_TIME_KEY_SWATCH	:break;
			case JBL_TIME_KEY_H12		:result=jbl_string_add_uint(result,tt.hour%12)				    ;break;
			case JBL_TIME_KEY_H12WZ		:result=jbl_string_add_uint_length(result,tt.hour%12,2,'0') 	;break;
			case JBL_TIME_KEY_H24		:result=jbl_string_add_uint(result,tt.hour)					    ;break;
			case JBL_TIME_KEY_H24WZ		:result=jbl_string_add_uint_length(result,tt.hour,2,'0')		;break;
			case JBL_TIME_KEY_MWZ		:result=jbl_string_add_uint_length(result,tt.minute,2,'0')	    ;break;
			case JBL_TIME_KEY_SWZ		:result=jbl_string_add_uint_length(result,tt.second,2,'0')	    ;break;
			case JBL_TIME_KEY_MSWZ		:result=jbl_string_add_uint_length(result,tt.ms,2,'0')		    ;break;
			
			
			case JBL_TIME_KEY_TZT		:result=jbl_string_add_chars(result,UC "GMT")					;break;
			case JBL_TIME_KEY_IDST		:break;
			case JBL_TIME_KEY_HTG		:break;
			case JBL_TIME_KEY_DWG		:break;
			case JBL_TIME_KEY_TZ		:break;
			case JBL_TIME_KEY_STG		:break;
			case JBL_TIME_KEY_S			:result=jbl_string_add_int(result,this->t/1000)				    ;break;

			
		}
	}
    jbl_refer_pull_unwrlock(result);
	return result;
}
jbl_string * jbl_time_to_string(jbl_time *this,jbl_string *result)
{
	return jbl_time_to_string_format(this,result,UC "Y-m-d H:i:s D");
}
#endif
#if JBL_STREAM_ENABLE==1
void jbl_stream_push_time(jbl_stream *out,jbl_time *this,const unsigned char * format)
{
	jbl_time_decoded tt;
	jbl_time_decode(this,&tt);
	jbl_string_size_type n=jbl_strlen(format),i=0;
	const unsigned char * addr;
	jbl_time_key key;
	const char * doms[]	={"th","st","nd","rd","th","th","th","th","th","th"};
	const char * dowa[]	={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
	const char * dow3[]	={"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
	const char * m[]	={"January","February","March","April","May","June","July","August","September","October","November","December"};
	const char * m3[]	={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
	const char * sa[]	={"am","pm"};
	const char * a[]	={"AM","PM"};
    jbl_refer_pull_wrlock(out);
	while((key=__jbl_time_key_scaner(format+i,format+n,&addr))!=JBL_TIME_KEY_END)
	{
		i=(jbl_string_size_type)(addr-format);
		switch(key)
		{
			case JBL_TIME_KEY_UNDEFINED	:jbl_stream_push_char(out,format[i-1])					;break;			
			case JBL_TIME_KEY_ESCAPE	:if(format[i])jbl_stream_push_char(out,format[i]),++i	;break;			
			case JBL_TIME_KEY_END		:return ;break;
			
			case JBL_TIME_KEY_DOM		:jbl_stream_push_uint(out,tt.day)						;break;
			case JBL_TIME_KEY_DOMWZ		:jbl_stream_push_uint_length(out,tt.day,2,'0')			;break;
			case JBL_TIME_KEY_DOMS		:jbl_stream_push_chars(out,UC doms[tt.day%10])			;break;
			case JBL_TIME_KEY_DOW3		:jbl_stream_push_chars(out,UC dow3[tt.week-1])			;break;
			case JBL_TIME_KEY_DOWA		:jbl_stream_push_chars(out,UC dowa[tt.week-1])			;break;
			case JBL_TIME_KEY_DOWN		:jbl_stream_push_uint(out,tt.week)						;break;
			case JBL_TIME_KEY_DOWNF0	:jbl_stream_push_uint(out,(jbl_uint8)(tt.week-1))       ;break;
			case JBL_TIME_KEY_DOY		:break;
			
			case JBL_TIME_KEY_WOY		:break;
			
			case JBL_TIME_KEY_M			:jbl_stream_push_chars(out,UC m[tt.month-1])			;break;	
			case JBL_TIME_KEY_MNWZ		:jbl_stream_push_uint_length(out,tt.month,2,'0')		;break;
			case JBL_TIME_KEY_M3		:jbl_stream_push_chars(out,UC m3[tt.month-1])			;break;	
			case JBL_TIME_KEY_MN		:jbl_stream_push_uint(out,tt.month)						;break;	
			case JBL_TIME_KEY_TDOM		:jbl_stream_push_uint(out,tt.dom)						;break;			

			case JBL_TIME_KEY_YILY		:jbl_stream_push_uint(out,tt.isleap)					;break;
			case JBL_TIME_KEY_Y			:jbl_stream_push_int_length(out,tt.year,4,'0')			;break;
			case JBL_TIME_KEY_YISO		:break;
			case JBL_TIME_KEY_Y2		:jbl_stream_push_int_length(out,tt.year%100,2,'0')		;break;	
			
			
			
			case JBL_TIME_KEY_SA		:jbl_stream_push_chars(out,UC sa[tt.hour/12])			;break;
			case JBL_TIME_KEY_A			:jbl_stream_push_chars(out,UC a[tt.hour/12])			;break;
			case JBL_TIME_KEY_SWATCH	:break;
			case JBL_TIME_KEY_H12		:jbl_stream_push_uint(out,tt.hour%12)					;break;
			case JBL_TIME_KEY_H12WZ		:jbl_stream_push_uint_length(out,tt.hour%12,2,'0')		;break;
			case JBL_TIME_KEY_H24		:jbl_stream_push_uint(out,tt.hour)						;break;
			case JBL_TIME_KEY_H24WZ		:jbl_stream_push_uint_length(out,tt.hour,2,'0')			;break;
			case JBL_TIME_KEY_MWZ		:jbl_stream_push_uint_length(out,tt.minute,2,'0')		;break;
			case JBL_TIME_KEY_SWZ		:jbl_stream_push_uint_length(out,tt.second,2,'0')		;break;
			case JBL_TIME_KEY_MSWZ		:jbl_stream_push_uint_length(out,tt.ms,2,'0')			;break;
			
			
			case JBL_TIME_KEY_TZT		:jbl_stream_push_chars(out,UC "GMT")					;break;
			case JBL_TIME_KEY_IDST		:break;
			case JBL_TIME_KEY_HTG		:break;
			case JBL_TIME_KEY_DWG		:break;
			case JBL_TIME_KEY_TZ		:break;
			case JBL_TIME_KEY_STG		:break;
			case JBL_TIME_KEY_S			:jbl_stream_push_int(out,this->t/1000)					;break;

			
		}
	}
    jbl_refer_pull_unwrlock(out);
}
#endif
#if JBL_JSON_ENABLE==1
/*******************************************************************************************/
/*                            以下函实现时间JSON操作                                      */
/*******************************************************************************************/
#if JBL_STRING_ENABLE==1
jbl_string* jbl_time_json_encode(jbl_time* this,jbl_string *out,jbl_uint8 format,jbl_uint32 tabs)
{
	jbl_time *thi=jbl_refer_pull_rdlock(this);
	out=jbl_string_json_put_format(thi,out,format,tabs);
    if(thi)
    {
        out=jbl_string_add_char(out,'"');
        out=jbl_time_to_string_format(this,out,UC "Y-m-d H:i:s D");
        out=jbl_string_add_char(out,'"');
        if(format&2){out=jbl_string_add_char(out,',');}if((format&1)||(format&4)){out=jbl_string_add_char(out,'\n');}
    }
    jbl_refer_pull_unwrlock(out);
    jbl_refer_pull_unrdlock(this);
	return out;
}
#endif
#if JBL_STREAM_ENABLE==1
void jbl_time_json_put(jbl_time* this,jbl_stream *out,jbl_uint8 format,jbl_uint32 tabs)
{
#if JBL_STRING_ENABLE==1
	jbl_string *s1=jbl_time_to_string_format(this,NULL,UC "Y-m-d H:i:s D");
	jbl_string_json_put(s1,out,format,tabs);
	jbl_string_free(s1);	
#else
	jbl_time *thi=jbl_refer_pull_rdlock(this);
	if(jbl_stream_json_put_format(thi,out,format,tabs))
    {
        jbl_stream_push_uint(out,thi->t);
        if(format&2){jbl_stream_push_char(out,',');}if((format&1)||(format&4)){jbl_stream_push_char(out,'\n');}
    }
    jbl_refer_pull_unwrlock(out);
    jbl_refer_pull_unrdlock(this);
#endif
}
#endif
#endif
#if JBL_STREAM_ENABLE==1
/*******************************************************************************************/
/*                            以下函数实现时间的浏览操作                                 */
/*******************************************************************************************/
jbl_time* jbl_time_view_put(jbl_time* this,jbl_stream *out,jbl_uint8 format,jbl_uint32 tabs,jbl_uint32 line,unsigned char * varname,unsigned char * func,unsigned char * file)
{
	jbl_time *thi=jbl_refer_pull_rdlock(this);
    if(jbl_stream_view_put_format(thi,out,format,tabs,UC"jbl_time",line,varname,func,file))
    {
        jbl_stream_push_chars(out,UC"\ttime stamp:");
        jbl_stream_push_int(out,thi->t);
        jbl_stream_push_time(out,thi,UC"\tY-m-d H:i:s.u");        
    }
    jbl_stream_push_char(out,'\n');
    jbl_refer_pull_unwrlock(out);
    jbl_refer_pull_unrdlock(this);
	return this;
}
#endif
#endif
